package io.renren.modules.sys.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.SysAccountEntity;
import io.renren.modules.sys.service.SysAccountService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-10-29 10:43:06
 */
@RestController
@RequestMapping("/sys/account")
public class SysAccountController {
	@Autowired
	private SysAccountService sysAccountService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("sys:account:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<SysAccountEntity> sysAccountList = sysAccountService.queryList(query);
		int total = sysAccountService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(sysAccountList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("sys:account:info")
	public R info(@PathVariable("id") Long id){
		SysAccountEntity sysAccount = sysAccountService.queryObject(id);
		
		return R.ok().put("sysAccount", sysAccount);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("sys:account:save")
	public R save(@RequestBody SysAccountEntity sysAccount){
		sysAccountService.save(sysAccount);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("sys:account:update")
	public R update(@RequestBody SysAccountEntity sysAccount){
		sysAccountService.update(sysAccount);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("sys:account:delete")
	public R delete(@RequestBody Long[] ids){
		sysAccountService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
